
/** for ChangeEvent */
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;

/** for ChangeListener */
import javax.swing.event.ChangeListener;

/**
 * This is a class to handle panel for MarketPlace
 * @author Code traders
 * @version 1.0
 */
public class MarketPlacePanel extends JPanel
implements ActionListener, ChangeListener, MainPanel {
	
	/**
	 * serialVersionUID for the MarketPlacePanel class
	 */
	private static final long serialVersionUID = -7215792635933192126L;
	
	/**
	 * Width and height for the JPanel
	 */
	private static final int WIDTH = 640, HEIGHT = 252;
	
	/**
	 * current MarketPlace
	 */
	private MarketPlace mp;
	
	/**
	 * Array of labels
	 */
	private final JLabel[] labels;
	
	/**
	 * JSpinners for the buySpinner and the sellSpinner
	 */
	private final JSpinner buySpinner, sellSpinner;
	
	/**
	 * ButtonGroup holding the JRadioButtons
	 */
	private final ButtonGroup chosen;
	
	/**
	 * JRadioButtons on the panel
	 */
	private final JRadioButton waterB, fursB, foodB,
	oreB, gamesB, firearmsB, medicineB,
	machinesB, narcoticsB, robotsB;
	
	/**
	 * Array holding the JRadioButtons
	 */
	private final JRadioButton[] buttons;
	
	/**
	 * JLabels for the buy and the sell
	 */
	private final JLabel buyTotal, sellTotal;
	
	/**
	 * current BottomPanel
	 */
	private BottomPanel bottom;
	
	/**
	 * Create the panel.
	 */
	public MarketPlacePanel() {
		
		super.setPreferredSize(new Dimension(WIDTH, HEIGHT));
		super.setOpaque(false);
		super.setLayout(null);
		
		final JLabel lblNewLabel = new JLabel("Items");
		lblNewLabel.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblNewLabel.setFont(new Font("Britannic Bold",
				Font.PLAIN, Numbers.SIXTEEN.getNumber()));
		lblNewLabel.setBounds(Numbers.EIGHTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TEN.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.FIFTY_THREE.getNumber() 
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblNewLabel);
		
		final JLabel lblWater = new JLabel("Water");
		lblWater.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblWater.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblWater.setBounds(Numbers.EIGHTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.FORTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblWater);
		
		final JLabel lblFurs = new JLabel("Furs");
		lblFurs.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblFurs.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblFurs.setBounds(Numbers.EIGHTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.FIVE.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblFurs);
		
		final JLabel lblFood = new JLabel("Food");
		lblFood.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblFood.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblFood.setBounds(Numbers.EIGHTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.SEVENTY_FIVE.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblFood);
		
		final JLabel lblOre = new JLabel("Ore");
		lblOre.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblOre.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblOre.setBounds(Numbers.EIGHTY.getNumber() +
				Numbers.TWO.getNumber(), Numbers.HUNDRED.getNumber()
				- Numbers.SIX.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblOre);
		
		final JLabel lblGames = new JLabel("Games");
		lblGames.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblGames.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblGames.setBounds(Numbers.EIGHTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.HUNDRED.getNumber()
				+ Numbers.EIGHT.getNumber() + Numbers.THREE.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(lblGames);
		
		final JLabel lblFirearms = new JLabel("Firearms");
		lblFirearms.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblFirearms.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblFirearms.setBounds(Numbers.EIGHTY.getNumber() +
				Numbers.TWO.getNumber(), Numbers.HUNDRED_FORTY.getNumber()
				- Numbers.TEN.getNumber(), Numbers.SEVENTY.getNumber() 
				+ Numbers.SIX.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblFirearms);
		
		final JLabel lblMedicine = new JLabel("Medicine");
		lblMedicine.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblMedicine.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblMedicine.setBounds(Numbers.EIGHTY.getNumber() +
				Numbers.TWO.getNumber(), Numbers.HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.SEVENTY.getNumber()
				+ Numbers.SIX.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblMedicine);
		
		final JLabel lblMachines = new JLabel("Machines");
		lblMachines.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblMachines.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblMachines.setBounds(Numbers.EIGHTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.HUNDRED_EIGHTY.getNumber()
				- Numbers.SEVEN.getNumber(), Numbers.SEVENTY.getNumber()
				+ Numbers.SIX.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblMachines);
		
		final JLabel lblNarcotics = new JLabel("Narcotics");
		lblNarcotics.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblNarcotics.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblNarcotics.setBounds(Numbers.EIGHTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED.getNumber()
				- Numbers.FIVE.getNumber(), Numbers.SEVENTY.getNumber() 
				+ Numbers.SIX.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblNarcotics);
		
		final JLabel lblRobots = new JLabel("Robots");
		lblRobots.setForeground(new Color(Numbers.HUNDRED.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblRobots.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblRobots.setBounds(Numbers.EIGHTY.getNumber() 
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED.getNumber()
				+ Numbers.FOUR.getNumber() + Numbers.TEN.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(lblRobots);
		
		final JLabel lblBuy = new JLabel("Available");
		lblBuy.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblBuy.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblBuy.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.EIGHTY_ONE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblBuy);
		
		final JLabel waterA = new JLabel("$");
		waterA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		waterA.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		waterA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.FORTY.getNumber() + Numbers.TWO.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(waterA);
		
		final JLabel fursA = new JLabel("$");
		fursA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		fursA.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		fursA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber() +
				Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.FIVE.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(fursA);
		
		final JLabel foodA = new JLabel("$");
		foodA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		foodA.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		foodA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber() 
				+ Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SEVENTY_FIVE.getNumber() + Numbers.TWO.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(foodA);
		
		final JLabel oreA = new JLabel("$");
		oreA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		oreA.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		oreA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber() +
				Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.HUNDRED.getNumber() - Numbers.SIX.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(oreA);
		
		final JLabel gamesA = new JLabel("$");
		gamesA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		gamesA.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		gamesA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber() +
				Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.HUNDRED.getNumber() + Numbers.EIGHT.getNumber() +
				Numbers.THREE.getNumber(), Numbers.FIFTY_THREE.getNumber() +
				Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(gamesA);
		
		final JLabel firearmsA = new JLabel("$");
		firearmsA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		firearmsA.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		firearmsA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber() +
				Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.HUNDRED_FORTY.getNumber() - Numbers.TEN.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(firearmsA);
		
		final JLabel medicineA = new JLabel("$");
		medicineA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		medicineA.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		medicineA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber() 
				+ Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.HUNDRED_FIFTY.getNumber() + Numbers.TWO.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(medicineA);
		
		final JLabel machinesA = new JLabel("$");
		machinesA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		machinesA.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		machinesA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.HUNDRED_EIGHTY.getNumber() - Numbers.SEVEN.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(machinesA);
		
		final JLabel narcoticsA = new JLabel("$");
		narcoticsA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		narcoticsA.setFont(new Font("Britannic Bold",
				Font.PLAIN, Numbers.SIXTEEN.getNumber()));
		narcoticsA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber() 
				+ Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.TWO_HUNDRED.getNumber() - Numbers.FIVE.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(narcoticsA);
		
		final JLabel robotsA = new JLabel("$");
		robotsA.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		robotsA.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		robotsA.setBounds(Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.TEN.getNumber() + Numbers.THREE.getNumber(),
				Numbers.TWO_HUNDRED.getNumber() + Numbers.FOUR.getNumber()
				+ Numbers.TEN.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(robotsA);
		
		final JLabel lblSell = new JLabel("Storage");
		lblSell.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber()
				+ Numbers.FIVE.getNumber(), 0));
		lblSell.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		lblSell.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber()
				- Numbers.EIGHT.getNumber(), Numbers.TEN.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(lblSell);
		
		final JLabel waterS = new JLabel("$");
		waterS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() +
				Numbers.FIVE.getNumber(), 0));
		waterS.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		waterS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.FORTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(waterS);
		
		final JLabel fursS = new JLabel("$");
		fursS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		fursS.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		fursS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber() +
				Numbers.TWO.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.FIVE.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(fursS);
		
		final JLabel foodS = new JLabel("$");
		foodS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		foodS.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		foodS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.SEVENTY_FIVE.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(foodS);
		
		final JLabel oreS = new JLabel("$");
		oreS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		oreS.setFont(new Font("Britannic Bold", Font.PLAIN, Numbers.SIXTEEN.getNumber()));
		oreS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.HUNDRED.getNumber()
				- Numbers.SIX.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(oreS);
		
		final JLabel gamesS = new JLabel("$");
		gamesS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		gamesS.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		gamesS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.HUNDRED.getNumber()
				+ Numbers.EIGHT.getNumber() + Numbers.THREE.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(gamesS);
		
		final JLabel firearmsS = new JLabel("$");
		firearmsS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		firearmsS.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		firearmsS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.HUNDRED_FORTY.getNumber()
				- Numbers.TEN.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(firearmsS);
		
		final JLabel medicineS = new JLabel("$");
		medicineS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		medicineS.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		medicineS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(medicineS);
		
		final JLabel machinesS = new JLabel("$");
		machinesS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		machinesS.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		machinesS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber() + 
				Numbers.TWO.getNumber(), Numbers.HUNDRED_EIGHTY.getNumber()
				- Numbers.SEVEN.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(machinesS);
		
		final JLabel narcoticsS = new JLabel("$");
		narcoticsS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		narcoticsS.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		narcoticsS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber() 
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED.getNumber()
				- Numbers.FIVE.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(narcoticsS);
		
		final JLabel robotsS = new JLabel("$");
		robotsS.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		robotsS.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		robotsS.setBounds(Numbers.THREE_HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED.getNumber()
				+ Numbers.FOUR.getNumber() + Numbers.TEN.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(robotsS);
		
		chosen = new ButtonGroup();
		
		waterB = new JRadioButton("");
		waterB.setOpaque(false);
		waterB.setBounds(Numbers.HUNDRED_FIFTY.getNumber() +
				Numbers.TWO.getNumber(), Numbers.FORTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.HUNDRED_TWENTY_EIGHT.getNumber() - 1,
				Numbers.TWENTY_FIVE.getNumber());
		waterB.addActionListener(this);
		waterB.setActionCommand("0");
		super.add(waterB);
		
		fursB = new JRadioButton("");
		fursB.setOpaque(false);
		fursB.setBounds(Numbers.HUNDRED_FIFTY.getNumber() +
				Numbers.TWO.getNumber(), Numbers.FIFTY_THREE.getNumber() +
				Numbers.FIVE.getNumber(), Numbers.HUNDRED_TWENTY_EIGHT.getNumber() - 1,
				Numbers.TWENTY_FIVE.getNumber());
		fursB.addActionListener(this);
		fursB.setActionCommand("1");
		super.add(fursB);
		
		foodB = new JRadioButton("");
		foodB.setOpaque(false);
		foodB.setBounds(Numbers.HUNDRED_FIFTY.getNumber() +
				Numbers.TWO.getNumber(), Numbers.SEVENTY_FIVE.getNumber() +
				Numbers.TWO.getNumber(), Numbers.HUNDRED_TWENTY_EIGHT.getNumber() - 1,
				Numbers.TWENTY_FIVE.getNumber());
		foodB.addActionListener(this);
		foodB.setActionCommand("2");
		super.add(foodB);
		
		oreB = new JRadioButton("");
		oreB.setOpaque(false);
		oreB.setBounds(Numbers.HUNDRED_FIFTY.getNumber() + Numbers.TWO.getNumber(),
				Numbers.HUNDRED.getNumber() - Numbers.SIX.getNumber(),
				Numbers.HUNDRED_TWENTY_EIGHT.getNumber() - 1,
				Numbers.TWENTY_FIVE.getNumber());
		oreB.addActionListener(this);
		oreB.setActionCommand("3");
		super.add(oreB);
		
		gamesB = new JRadioButton("");
		gamesB.setOpaque(false);
		gamesB.setBounds(Numbers.HUNDRED_FIFTY.getNumber() + Numbers.TWO.getNumber(),
				Numbers.HUNDRED.getNumber() +
				Numbers.EIGHT.getNumber() + Numbers.THREE.getNumber(),
				Numbers.HUNDRED_TWENTY_EIGHT.getNumber() - 1,
				Numbers.TWENTY_FIVE.getNumber());
		gamesB.addActionListener(this);
		gamesB.setActionCommand("4");
		super.add(gamesB);
		
		firearmsB = new JRadioButton("");
		firearmsB.setOpaque(false);
		firearmsB.setBounds(Numbers.HUNDRED_FIFTY.getNumber()
				+ Numbers.TWO.getNumber(), Numbers.HUNDRED_FORTY.getNumber()
				- Numbers.TEN.getNumber(), Numbers.HUNDRED_TWENTY_EIGHT.getNumber()
				- 1, Numbers.TWENTY_FIVE.getNumber());
		firearmsB.addActionListener(this);
		firearmsB.setActionCommand("5");
		super.add(firearmsB);
		
		medicineB = new JRadioButton("");
		medicineB.setOpaque(false);
		medicineB.setBounds(Numbers.HUNDRED_FIFTY.getNumber() + Numbers.TWO.getNumber(),
				Numbers.HUNDRED_FIFTY.getNumber() + Numbers.TWO.getNumber(),
				Numbers.HUNDRED_TWENTY_EIGHT.getNumber() - 1,
				Numbers.TWENTY_FIVE.getNumber());
		medicineB.addActionListener(this);
		medicineB.setActionCommand("6");
		super.add(medicineB);
		
		machinesB = new JRadioButton("");
		machinesB.setOpaque(false);
		machinesB.setBounds(Numbers.HUNDRED_FIFTY.getNumber() 
				+ Numbers.TWO.getNumber(), Numbers.HUNDRED_EIGHTY.getNumber()
				- Numbers.SEVEN.getNumber(), Numbers.HUNDRED_TWENTY_EIGHT.getNumber() - 1,
				Numbers.TWENTY_FIVE.getNumber());
		machinesB.addActionListener(this);
		machinesB.setActionCommand("7");
		super.add(machinesB);
		
		narcoticsB = new JRadioButton("");
		narcoticsB.setOpaque(false);
		narcoticsB.setBounds(Numbers.HUNDRED_FIFTY.getNumber() 
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED.getNumber()
				- Numbers.FIVE.getNumber(), Numbers.HUNDRED_TWENTY_EIGHT.getNumber() - 1,
				Numbers.TWENTY_FIVE.getNumber());
		narcoticsB.addActionListener(this);
		narcoticsB.setActionCommand("8");
		super.add(narcoticsB);
		
		robotsB = new JRadioButton("");
		robotsB.setOpaque(false);
		robotsB.setBounds(Numbers.HUNDRED_FIFTY.getNumber() 
				+ Numbers.TWO.getNumber(), Numbers.TWO_HUNDRED.getNumber()
				+ Numbers.FOUR.getNumber() + Numbers.TEN.getNumber(),
				Numbers.HUNDRED_TWENTY_EIGHT.getNumber() - 1,
				Numbers.TWENTY_FIVE.getNumber());
		robotsB.addActionListener(this);
		robotsB.setActionCommand("9");
		super.add(robotsB);
		
		chosen.add(waterB);
		chosen.add(fursB);
		chosen.add(foodB);
		chosen.add(oreB);
		chosen.add(gamesB);
		chosen.add(firearmsB);
		chosen.add(medicineB);
		chosen.add(machinesB);
		chosen.add(narcoticsB);
		chosen.add(robotsB);
		
		buttons = new JRadioButton[]{waterB, fursB, foodB,
				oreB, gamesB, firearmsB, medicineB,
				machinesB, narcoticsB, robotsB};
		
		buySpinner = new JSpinner();
		buySpinner.setFont(new Font("Palatino Linotype", Font.BOLD,
				Numbers.TEN.getNumber() + Numbers.FIVE.getNumber()));
		buySpinner.setBorder(null);
		buySpinner.setModel(new SpinnerNumberModel
				(0, 0, Numbers.TWENTY.getNumber(), 1));
		buySpinner.setBackground(new Color(Numbers.HUNDRED.getNumber()
				- Numbers.FIVE.getNumber(), Numbers.HUNDRED_SIXTY.getNumber()
				- Numbers.TWO.getNumber(), Numbers.HUNDRED_SIXTY.getNumber()));
		buySpinner.setOpaque(false);
		buySpinner.setBounds(Numbers.FOUR_HUNDRED.getNumber() + 1,
				Numbers.HUNDRED_TWENTY_EIGHT.getNumber(),
				Numbers.FORTY_FOUR.getNumber() + 1,
				Numbers.TWENTY_FIVE.getNumber());
		buySpinner.addChangeListener(this);
		super.add(buySpinner);
		
		sellSpinner = new JSpinner();
		sellSpinner.setOpaque(false);
		sellSpinner.setFont(new Font("Palatino Linotype", Font.BOLD,
				Numbers.TEN.getNumber() + Numbers.FIVE.getNumber()));
		sellSpinner.setBorder(null);
		sellSpinner.setBackground(
				new Color(Numbers.HUNDRED.getNumber() - Numbers.FIVE.getNumber(),
						Numbers.HUNDRED_SIXTY.getNumber() - Numbers.TWO.getNumber(),
						Numbers.HUNDRED_SIXTY.getNumber()));
		sellSpinner.setModel(new SpinnerNumberModel(0, 0, Numbers.TWENTY.getNumber(), 1));
		sellSpinner.setBounds(Numbers.FOUR_HUNDRED.getNumber() + 1,
				Numbers.HUNDRED_SIXTY.getNumber() + Numbers.FOUR.getNumber(),
				Numbers.FORTY_FOUR.getNumber() + 1,
				Numbers.TWENTY_FIVE.getNumber());
		sellSpinner.addChangeListener(this);
		super.add(sellSpinner);
		
		final JButton btnBuy = new JButton();
		btnBuy.setSelectedIcon(new ImageIcon
				(MarketPlacePanel.class.getResource("/image/buy_pressed.png")));
		btnBuy.setPressedIcon(new ImageIcon
				(MarketPlacePanel.class.getResource("/image/buy_pressed.png")));
		btnBuy.setOpaque(false);
		btnBuy.setIcon(new ImageIcon
				(MarketPlacePanel.class.getResource("/image/buy.png")));
		btnBuy.setBounds(Numbers.FIVE_HUNDRED.getNumber() + Numbers.FIVE.getNumber()
				+ Numbers.TEN.getNumber(), Numbers.HUNDRED_FORTY.getNumber()
				- Numbers.TEN.getNumber(), Numbers.NINTY_SEVEN.getNumber(),
				Numbers.TWENTY_FIVE.getNumber());
		btnBuy.setContentAreaFilled(false);
		btnBuy.setBorderPainted(false);
		btnBuy.setActionCommand("buy");
		btnBuy.addActionListener(this);
		super.add(btnBuy);
		
		final JButton btnSell = new JButton();
		btnSell.setIcon(new ImageIcon
				(MarketPlacePanel.class.getResource("/image/sell.png")));
		btnSell.setOpaque(false);
		btnSell.setSelectedIcon(new ImageIcon
				(MarketPlacePanel.class.getResource("/image/sell_pressed.png")));
		btnSell.setPressedIcon(new ImageIcon
				(MarketPlacePanel.class.getResource("/image/sell_pressed.png")));
		btnSell.setBounds(Numbers.FIVE_HUNDRED.getNumber() +
				Numbers.FIVE.getNumber() + Numbers.TEN.getNumber(),
				Numbers.HUNDRED_SIXTY.getNumber() + Numbers.FOUR.getNumber(),
				Numbers.NINTY_SEVEN.getNumber(), Numbers.TWENTY_FIVE.getNumber());
		btnSell.setContentAreaFilled(false);
		btnSell.setBorderPainted(false);
		btnSell.setActionCommand("sell");
		btnSell.addActionListener(this);
		super.add(btnSell);
		
		buyTotal = new JLabel("0");
		buyTotal.setForeground(new Color
				(0, Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		buyTotal.setFont(new Font
				("Britannic Bold", Font.PLAIN, Numbers.SIXTEEN.getNumber()));
		buyTotal.setBounds(Numbers.FOUR_HUNDRED.getNumber() +
				Numbers.SIXTY.getNumber(), Numbers.HUNDRED_FORTY.getNumber()
				- Numbers.TEN.getNumber(), Numbers.FIFTY_THREE.getNumber() +
				Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(buyTotal);
		
		sellTotal = new JLabel("0");
		sellTotal.setForeground(new Color
				(Numbers.HUNDRED.getNumber() + Numbers.TWO.getNumber(),
						Numbers.TWO_HUNDRED_FIFTY.getNumber() +
						Numbers.FIVE.getNumber(), 0));
		sellTotal.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		sellTotal.setBounds(Numbers.FOUR_HUNDRED.getNumber() +
				Numbers.SIXTY.getNumber(), Numbers.HUNDRED_SIXTY.getNumber() 
				+ Numbers.FOUR.getNumber(), Numbers.FIFTY_THREE.getNumber() +
				Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(sellTotal);
		
		final JLabel waterP = new JLabel("$");
		waterP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() +
				Numbers.FIVE.getNumber(), 0));
		waterP.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		waterP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() + 1,
				Numbers.FORTY.getNumber() + Numbers.TWO.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(waterP);
		
		final JLabel fursP = new JLabel("$");
		fursP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		fursP.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		fursP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() + 1,
				Numbers.FIFTY_THREE.getNumber() + Numbers.FIVE.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(fursP);
		
		final JLabel foodP = new JLabel("$");
		foodP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		foodP.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		foodP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() + 1,
				Numbers.SEVENTY_FIVE.getNumber() + Numbers.TWO.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(foodP);
		
		final JLabel oreP = new JLabel("$");
		oreP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		oreP.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		oreP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() + 1,
				Numbers.HUNDRED.getNumber() - Numbers.SIX.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(oreP);
		
		final JLabel gamesP = new JLabel("$");
		gamesP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		gamesP.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		gamesP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() + 1,
				Numbers.HUNDRED.getNumber() + Numbers.EIGHT.getNumber() 
				+ Numbers.THREE.getNumber(), Numbers.FIFTY_THREE.getNumber()
				+ Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(gamesP);
		
		final JLabel firearmsP = new JLabel("$");
		firearmsP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(), 
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		firearmsP.setFont(new Font("Britannic Bold", Font.PLAIN, 
				Numbers.SIXTEEN.getNumber()));
		firearmsP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() + 1,
				Numbers.HUNDRED_FORTY.getNumber() - Numbers.TEN.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(firearmsP);
		
		final JLabel medicineP = new JLabel("$");
		medicineP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		medicineP.setFont(new Font("Britannic Bold", Font.PLAIN, 
				Numbers.SIXTEEN.getNumber()));
		medicineP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() + 1,
				Numbers.HUNDRED_FIFTY.getNumber() + Numbers.TWO.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(), 
				Numbers.SIXTEEN.getNumber());
		super.add(medicineP);
		
		final JLabel machinesP = new JLabel("$");
		machinesP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		machinesP.setFont(new Font("Britannic Bold", Font.PLAIN,
				Numbers.SIXTEEN.getNumber()));
		machinesP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() + 1,
				Numbers.HUNDRED_EIGHTY.getNumber() - Numbers.SEVEN.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(machinesP);
		
		final JLabel narcoticsP = new JLabel("$");
		narcoticsP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		narcoticsP.setFont(new Font("Britannic Bold", Font.PLAIN, 
				Numbers.SIXTEEN.getNumber()));
		narcoticsP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() + 1,
				Numbers.TWO_HUNDRED.getNumber() - Numbers.FIVE.getNumber(),
				Numbers.FIFTY_THREE.getNumber() + Numbers.THREE.getNumber(),
				Numbers.SIXTEEN.getNumber());
		super.add(narcoticsP);
		
		final JLabel robotsP = new JLabel("$");
		robotsP.setForeground(new Color(Numbers.FIFTY_ONE.getNumber(),
				Numbers.TWO_HUNDRED_FIFTY.getNumber() + Numbers.FIVE.getNumber(), 0));
		robotsP.setFont(new Font("Britannic Bold",
				Font.PLAIN, Numbers.SIXTEEN.getNumber()));
		robotsP.setBounds(Numbers.HUNDRED_EIGHTY_EIGHT.getNumber() +
				1, Numbers.TWO_HUNDRED.getNumber() + Numbers.FOUR.getNumber() +
				Numbers.TEN.getNumber(), Numbers.FIFTY_THREE.getNumber() +
				Numbers.THREE.getNumber(), Numbers.SIXTEEN.getNumber());
		super.add(robotsP);
		
		labels = new JLabel[]{waterP, fursP, foodP, oreP, gamesP,
				firearmsP, medicineP, machinesP, narcoticsP, robotsP, 
				waterA, fursA, foodA, oreA, gamesA, firearmsA, medicineA,
				machinesA, narcoticsA, robotsA, waterS, fursS, foodS, oreS,
				gamesS, firearmsS, medicineS, machinesS, narcoticsS, robotsS};
	}
	
	/**
	 * Updates the panel with the appropriate updated information.
	 */
	@Override
	public void update() {
		final Goods[] goods = mp.getGoods();
		final Ship ship = mp.getShip();
		for (int i = 0; i < Goods.values().length; i++) {
			labels[i].setText("" + goods[i].getPrice());
		}
		final int num = Goods.values().length;
		for (int i = num; 
				i < Goods.values().length * Numbers.TWO.getNumber(); i++) {
			labels[i].setText("" + goods[i - Goods.values().length].getAmount());
		}
		for (int i = Goods.values().length * Numbers.TWO.getNumber(); i <
				Goods.values().length * Numbers.THREE.getNumber(); i++) {
			labels[i].setText("" + ship.getGoods()
					[i - Goods.values().length * Numbers.TWO.getNumber()]);
		}
		bottom.updateBottomPanel("store");
//		main.setMarketPlace(mp);
//		Singleton.INSTANCE.put("mp", mp); // Singleton
	}
	
	/**
	 * Setter for the MarketPlace.
	 * 
	 * @param mp MarketPlace object
	 */
	public void setMarketPlace(MarketPlace mp) {
		this.mp = mp;
	}
	
	/**
	 * Setter for the current BottomPanel object.
	 * 
	 * @param bp current BottomPanel object
	 */
	public void setBottomPanel(BottomPanel bp) {
		this.bottom = bp;
	}

	/**
	 * ActionListener for the JComponents
	 * 
	 * @param e ActionEvent object for the JComponent
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		final Goods[] goods = mp.getGoods();
		final Ship ship = mp.getShip();
		if (e.getSource() instanceof JRadioButton) {
			try {
				final int currentNum = Integer.parseInt(e.getActionCommand());
				buySpinner.setModel(new SpinnerNumberModel
						(0, 0, goods[currentNum].getAmount(), 1));
				sellSpinner.setModel(new SpinnerNumberModel(0, 0, 
						ship.getGoods()[Integer.parseInt(e.getActionCommand())], 1));
			} catch (NumberFormatException err) {
				err.printStackTrace();
			}
		} else if (e.getSource() instanceof JButton) {
			if (getSelectedIndex() == -1) return;
			if (e.getActionCommand().equals("buy")) {
				if (!mp.canBuy(goods[getSelectedIndex()], (int) buySpinner.getValue())) {
					JOptionPane.showMessageDialog
					(this, mp.getErrorMsg(), "Failed to buy", JOptionPane.ERROR_MESSAGE);
				}
			} else {
				if (!mp.canSell(goods[getSelectedIndex()], 
						(int) sellSpinner.getValue())) {
					JOptionPane.showMessageDialog
					(this, mp.getErrorMsg(), "Failed to sell", JOptionPane.ERROR_MESSAGE);
				}
			}
			buySpinner.setModel(new SpinnerNumberModel
					(0, 0, goods[getSelectedIndex()].getAmount(), 1));
			sellSpinner.setModel(new SpinnerNumberModel
					(0, 0, ship.getGoods()[getSelectedIndex()], 1));
			buyTotal.setText("0");
			sellTotal.setText("0");
		}
		update();
	}
	
	/**
	 * Get the current selected index for the JRadioButton. 
	 * 
	 * @return current selected index for the JRadioButton
	 */
	private int getSelectedIndex() {
		for (int i = 0; i < buttons.length; i++) {
			if (buttons[i].isSelected()) {
				return i;
			}
		}
		return -1;
	}

	/**
	 * ChangeListener for the JSpinners. 
	 * Update the related labels with the changed value when changed. 
	 * 
	 * @param e ChangeEvent object for the JSpinner
	 */
	@Override
	public void stateChanged(ChangeEvent e) {
		if (getSelectedIndex() == -1) return;
		final Goods[] goods = mp.getGoods();
		if (e.getSource().equals(buySpinner)) {
			buyTotal.setText("" + goods[getSelectedIndex()].getPrice()
					* ((int) ((JSpinner) e.getSource()).getValue()));
		} else {
			sellTotal.setText("" + goods[getSelectedIndex()].getPrice()
					* ((int) ((JSpinner) e.getSource()).getValue()));
		}
	}
}
